<?php

require_once dirname(__FILE__).'/../class/functions.php';
require_once dirname(__FILE__).'/../class/user.class.php';

$a = session_id();if(empty($a)) session_start();

$logat = is_logat();
mysql_safer();
$show='';
if($logat == 0)
    die("Nu v-ati logat");
else
{
    if( $_SESSION['logat'] == "admin" )
    {            
        $user=unserialize($_SESSION['userc']);
        $adm=1;
    }
    else die("Interzis utilizatorilor normali!(Nu aveti drepturi!)");
    
}

if(isset($_GET['action'])){
    
    if(!strcmp($_GET['action'],"add")){
        if(strlen($_POST['titlu'])<5 || strlen($_POST['continut'])<5) die("Date Invalide!");
        $user=unserialize($_SESSION['userc']);
       $_POST['continut']=  str_replace("\\r\\n", "<br>", $_POST['continut']);
        $query="INSERT INTO `news` (`NID`, `TITLU`, `CONTINUT`, `UID`, `DATA`) VALUES (NULL,  '".$_POST['titlu']."', '".$_POST['continut']."', '$user->id', '".date("Y-m-d", time())."')";
        //echo $query;
        $db->q($query);
        $show="<p> Articolul a fost publicat! </p> <br />";
        
        
    }
    
    
    
}

?>


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="icon" href="favicon.jpg" type="image/gif" sizes="16x16" /> 
        <link rel="stylesheet" type="text/css" href="../style/style.css" />
        <title>Panou Administriv - Noutati</title>
    </head>
<body>
    <? 
      what_header();
      footer(1);
        ?>
        <div id="content">
            <div id="content_inside">
                    <div id="content_inside_sidebar">
                        <ul>
                            <li><a href ="../index.php"> Home</a><br /></li>
                            <li><a href ="admin.php"> Panou Principal</a><br /></li>
                            <li><a href ="p_news.php"> Noutati</a><br /></li>  
                            <li><a href ="p_rezervari.php"> Rezervari</a><br /></li>
                            <li><a href ="p_downloads.php"> Downloads</a><br /></li>                   
                                           
                         </ul>
                                 
                    </div>
            <div id="content_inside_main">
                <?  echo $show;  ?>
                <form method="post" action="p_news.php?action=add" class="news_form">
                    <input type ="text" name="titlu" value="Titlu" class="news_elem"><br>
                    <textarea name="continut" class="news_elem" rows="30"> </textarea><br>
                    <input type="submit" value="Posteaza!"><br>
                </form>                        
                                 
            </div>
            </div>
            
        </div>

</body>

<? //  echo " path = " . $path; 
?>
</html>